﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace MoonLight.LibCommon
{
    public class CmdPipe
    {
        public static string StartCmd(string command)
        {  
            string output = "";
            try
            {
                Process cmd = new Process();
                cmd.StartInfo.FileName = command;
                cmd.StartInfo.UseShellExecute = false;
                cmd.StartInfo.RedirectStandardInput = true;
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.CreateNoWindow = true;
                cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                cmd.Start();
                output = cmd.StandardOutput.ReadToEnd();
                cmd.WaitForExit();
                cmd.Close();
            }
            catch(Exception ex)
            {
                Logger.WriteLog(ex.Message);
            }
            return output;  
         }  

         public static string StartCmdArgs(string command, string argument)  
         {
             string output = "";
             try
             {
                 Process cmd = new Process();
                 cmd.StartInfo.FileName = command;
                 cmd.StartInfo.Arguments = argument;
                 cmd.StartInfo.UseShellExecute = false;
                 cmd.StartInfo.RedirectStandardInput = true;
                 cmd.StartInfo.RedirectStandardOutput = true;
                 cmd.StartInfo.CreateNoWindow = true;
                 cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                 cmd.Start();
                 output = cmd.StandardOutput.ReadToEnd();
                 cmd.WaitForExit();
                 cmd.Close();
             }
             catch (Exception ex)
             {
                 Logger.WriteLog(ex.Message);
             }
             return output;  
         }  
    }
}
